#!/bin/bash

echo "开始安装获取阿里云docker镜像。。"
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun > /dev/null 2>&1
echo "导入完成，开始安装必要插件。。"
yum install -y yum-utils device-mapper-persistent-data lvm2 > /dev/null 2>&1
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo > /dev/null 2>&1
echo "yum缓存中。。"
yum makecache fast > /dev/null 2>&1
echo "开始安装docker-ce"
yum -y install docker-ce > /dev/null 2>&1
echo "启动docker并设置为开机自启"
systemctl start docker
systemctl enable docker > /dev/null 2>&1
echo "docker版本如下"
docker -v

echo "修改参数，开启相关转发功能,修改后内容如下"
echo "由于网桥工作在数据链路层，在iptables没有开启bridge-nf时，数据会直接经过网桥转发，结果就是对FORWARD的设置失效"
cat > /etc/sysctl.d/k8s.conf  <<EOF
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.ip_forward=1
EOF
cat /etc/sysctl.d/k8s.conf
sysctl -p

echo "配置docker自动补全"
source /usr/share/bash-completion/completions/docker
yum install -y bash-completion > /dev/null 2>&1
sh /usr/share/bash-completion/bash_completion > /dev/null 2>&1
echo "配置完成，请重新开启一个新的shell终端即可生效"